package com.ymatou.iapi.productprice.testcase;

import com.google.gson.JsonObject;
import com.shop2cn.iapi.activitymgt.parameter.AddactivityBean;
import com.shop2cn.iapi.agentproducts.parameter.AddAgentProductBean;
import com.shop2cn.iapi.agentproducts.parameter.ProductDetailsDto;
import com.ymatou.iapi.prodstock.parameter.PCatalogListDto;
import com.ymatou.iapi.productprice.parameter.ProductAllPriceBean;
import com.ymatou.iapi.productprice.parameter.ProductPriceBean;
import com.ymatou.iapi.productprice.service.GetNextActivityPriceByProdIdsCall;
import com.ymatou.iapi.productquery.parameter.GetProductInfoByProductIdBean;
import com.ymatou.iapi.productquery.service.GetProductInfoByProductIdCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.tag.P1;
import com.ymttest.business.service.*;
import com.ymttest.database.mongo.YmtMongoDriverFactroy;
import com.ymttest.database.mongo.jproduct.ActivityProductsWapper;
import com.ymttest.database.mongo.jproduct.ProductsWapperV2;
import com.ymttest.database.sqlwapper.YmtCatalogsIWapper;
import com.ymttest.utils.AgentUsers;
import com.ymttest.utils.EnvSetup;
import com.ymttest.utils.MapUtil;
import com.ymttest.utils.YMTDateUtil;
import org.json.JSONException;
import org.json.JSONObject;
import org.junit.*;
import org.junit.experimental.categories.Category;

import java.io.IOException;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;


public class Ts_GetNextActivityPriceByProdIds {
	// 3332634 level 0 registerTime 2015-05-26 14:20:04
	private static int newBuyerId = ProductPriceCallService.getNewCustomer();

	// 20238699 level 6 registerTime 2016-04-22 10:19:05
	private static int oldBuyerId = ProductPriceCallService.getOldCustomer();

	
	private static Integer sellerId = Integer.valueOf(EnvSetup.getData("productpriceSellerId"));
	
	
	private static GetNextActivityPriceByProdIdsCall getNextActivityPriceByProdIdsCall = new GetNextActivityPriceByProdIdsCall();

	private static ActivityProductsWapper activityProductsWapper = new ActivityProductsWapper();
	
	
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("下一场活动商品的价格查询");
		try {
			GodfreightmgrService.deleteBySellerId(rootUserId);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	@Before
	public void caseUp() {

	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(getNextActivityPriceByProdIdsCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	
	public static void checkRetAsNoPrice(JSONObject ret,String desc) throws JSONException{
		Logger.verifyEquals(0, ret.getJSONObject("Data").getJSONArray("ProductPriceList").length(), desc);
	}

	/*请求参数：
   {"ProductActivityList":[{"ProductInActivityId":578553,"ProductId":"p5400395"}],"BuyerId":20238699,"IsTradeIsolation":true}
   IsTradeIsolation:是否是交易隔离
 */
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetNextActivityPriceByProdIds_001() {
		Logger.start(true, "非交易隔离的会员活动");
		try {
			String productId = ProductPriceCallService.getProductIdWithAllPrice();
			
			ProductAllPriceBean productAllPriceBean = ProductPriceCallService.getProdPriceWithActivityInFuture(sellerId,
								productId,MapUtil.hashMap("ActivityTemplateId", ProductPriceCallService.tpl_Nisolation_Npartcatalog_Nnewbuyer_Member));
			

			Thread.sleep(2000);
			if (YmtMongoDriverFactroy.IsNewJavaMongoOpen){
			new ActivityProductsWapper().update(productAllPriceBean.getProductId(), MapUtil.hashMap("part",false,"nbuyer",false,"isolation",false));
			}
			
					
			int prodInActivityId = Integer.parseInt(activityProductsWapper.getByProdId(productId).get("inaid").toString());

			//新客 会员价
			ProductPriceBean priceIncludeActivity_NewCust = ProductPriceCallService.getProductPriceBeanByUserLevel(productAllPriceBean,true,false);
			//老客 会员价
			ProductPriceBean priceIncludeActivity_OleCust = ProductPriceCallService.getProductPriceBeanByUserLevel(productAllPriceBean,false,false);
			
			
			//==================================================================================
			//会员政策1， 会员等级3以上才能享受活动价
			ProductPriceCallService.updateActivityMemberPolicy(prodInActivityId, 1, "3,4,5,6");
			
			//IsTradeIsolation= true
			//0级会员 新客 无返回
			Logger.comment("############### (会员政策1， 会员等级3以上才能享受活动价),0级会员 新客 无返回 IsTradeIsolation:true  ");
			JSONObject ret1_1 = getNextActivityPriceByProdIdsCall.callAndGetReturnData(newBuyerId,true,MapUtil.hashMap(productId, prodInActivityId));
			checkRetAsNoPrice(ret1_1, "不满足会员条件，不返回数据");
			
			//6级会员  老客 会员活动价
			Logger.comment("############### (会员政策1， 会员等级3以上才能享受活动价),6级会员  老客 会员活动价 IsTradeIsolation:true ");
			JSONObject ret1_2 = getNextActivityPriceByProdIdsCall.callAndGetReturnData(oldBuyerId,true,MapUtil.hashMap(productId, prodInActivityId));
			ProductPriceCallService.checkPriceList(ret1_2, Arrays.asList(priceIncludeActivity_OleCust));
			
			//IsTradeIsolation= false
			//0级会员 新客 无返回
			Logger.comment("############### (会员政策1， 会员等级3以上才能享受活动价),0级会员 新客 无返回 IsTradeIsolation:false ");
			JSONObject ret1_3 = getNextActivityPriceByProdIdsCall.callAndGetReturnData(newBuyerId,false,MapUtil.hashMap(productId, prodInActivityId));
			checkRetAsNoPrice(ret1_3, "不满足会员条件，不返回数据");
			
			//6级会员  老客 会员活动价
			Logger.comment("############### (会员政策1， 会员等级3以上才能享受活动价),6级会员  老客 会员活动价 IsTradeIsolation:false ");
			JSONObject ret1_4 = getNextActivityPriceByProdIdsCall.callAndGetReturnData(oldBuyerId,false,MapUtil.hashMap(productId, prodInActivityId));
			ProductPriceCallService.checkPriceList(ret1_4, Arrays.asList(priceIncludeActivity_OleCust));
			
			//==================================================================================
			//会员政策2，会员注册时间在2017-01-02 到 2017-03-23 才能享受活动价
			Logger.comment("############### （会员政策2，会员注册时间在2017-01-02 到 2017-03-23 才能享受活动价）会员注册时间在2017-01-02 到 2017-03-23 才能享受活动价 ");
			ProductPriceCallService.updateActivityMemberPolicy(prodInActivityId, 2, "2017-01-02 00:00:00,2018-03-23 23:59:59");
			
			//IsTradeIsolation= false
			//新客 注册时间2015-05-26 14:20:04 会员活动价
			Logger.comment("############### （会员政策2，会员注册时间在2017-01-02 到 2017-03-23 才能享受活动价）新客 注册时间2015-05-26 14:20:04 会员活动价 IsTradeIsolation= false");
			JSONObject ret2_1 = getNextActivityPriceByProdIdsCall.callAndGetReturnData(newBuyerId, true,MapUtil.hashMap(productId, prodInActivityId));
			ProductPriceCallService.checkPriceList(ret2_1, Arrays.asList(priceIncludeActivity_NewCust));
			
			//老客 注册时间2016-04-22 10:19:05 不返回数据
			Logger.comment("############### （会员政策2，会员注册时间在2017-01-02 到 2017-03-23 才能享受活动价）老客 注册时间2016-04-22 10:19:05 不返回数据 IsTradeIsolation= false");
			JSONObject ret2_2 = getNextActivityPriceByProdIdsCall.callAndGetReturnData(oldBuyerId, true,MapUtil.hashMap(productId, prodInActivityId));
			checkRetAsNoPrice(ret2_2, "不满足会员条件，不返回数据");
			
			//IsTradeIsolation= false
			//新客 注册时间2015-05-26 14:20:04 会员活动价
			Logger.comment("############### （会员政策2，会员注册时间在2017-01-02 到 2017-03-23 才能享受活动价）新客 注册时间2015-05-26 14:20:04 会员活动价 IsTradeIsolation= false ");
			JSONObject ret2_3 = getNextActivityPriceByProdIdsCall.callAndGetReturnData(newBuyerId, false,MapUtil.hashMap(productId, prodInActivityId));
			ProductPriceCallService.checkPriceList(ret2_3, Arrays.asList(priceIncludeActivity_NewCust));
			
			//老客 注册时间2016-04-22 10:19:05 不返回数据
			Logger.comment("############### （会员政策2，会员注册时间在2017-01-02 到 2017-03-23 才能享受活动价）老客 注册时间2016-04-22 10:19:05 不返回数据 IsTradeIsolation= false ");
			JSONObject ret2_4 = getNextActivityPriceByProdIdsCall.callAndGetReturnData(oldBuyerId, false,MapUtil.hashMap(productId, prodInActivityId));
			checkRetAsNoPrice(ret2_4, "不满足会员条件，不返回数据");
			
		
			//==================================================================================
			//会员政策3， 会员标签满足才能享受活动价  标签值 3 
			ProductPriceCallService.updateActivityMemberPolicy(prodInActivityId,3, "3");
			
			//IsTradeIsolation= true
			//新客 标签3  会员活动价
			Logger.comment("############### （会员政策3， 会员标签满足才能享受活动价  标签值 3 ) 新客 标签3  会员活动价 IsTradeIsolation= true");
			JSONObject ret3_1 = getNextActivityPriceByProdIdsCall.callAndGetReturnData(newBuyerId, true,MapUtil.hashMap(productId, prodInActivityId));
			ProductPriceCallService.checkPriceList(ret3_1, Arrays.asList(priceIncludeActivity_NewCust));
			
			//老客 没标签 不返回数据
			Logger.comment("############### （会员政策3， 会员标签满足才能享受活动价  标签值 3 ) 老客 没标签 不返回数据 IsTradeIsolation= true");
			JSONObject ret3_2 = getNextActivityPriceByProdIdsCall.callAndGetReturnData(oldBuyerId, true,MapUtil.hashMap(productId, prodInActivityId));
			checkRetAsNoPrice(ret3_2, "不满足会员条件，不返回数据");
			
			//IsTradeIsolation= false
			//新客 标签3  会员活动价
			Logger.comment("############### （会员政策3， 会员标签满足才能享受活动价  标签值 3 ) 新客 标签3  会员活动价 IsTradeIsolation= false");
			JSONObject ret3_3 = getNextActivityPriceByProdIdsCall.callAndGetReturnData(newBuyerId, false,MapUtil.hashMap(productId, prodInActivityId));
			ProductPriceCallService.checkPriceList(ret3_3, Arrays.asList(priceIncludeActivity_NewCust));
			
			//老客 没标签 不返回数据
			Logger.comment("############### （会员政策3， 会员标签满足才能享受活动价  标签值 3 ) 老客 没标签 不返回数据 IsTradeIsolation= false");
			JSONObject ret3_4 = getNextActivityPriceByProdIdsCall.callAndGetReturnData(oldBuyerId, false,MapUtil.hashMap(productId, prodInActivityId));
			checkRetAsNoPrice(ret3_4, "不满足会员条件，不返回数据");
			
			
			//==============================================================================================
			//会员政策3， 会员标签满足才能享受活动价  标签值 4
			ProductPriceCallService.updateActivityMemberPolicy(prodInActivityId,3, "4");
			
			//新客  标签3  普通价
			Logger.comment("############### （会员政策3， 会员标签满足才能享受活动价  标签值 4 ) 新客  标签3  普通价 IsTradeIsolation= true");
			JSONObject ret4 =getNextActivityPriceByProdIdsCall.callAndGetReturnData(newBuyerId,true,MapUtil.hashMap(productId, prodInActivityId));
			checkRetAsNoPrice(ret4, "不满足会员条件，不返回数据");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetNextActivityPriceByProdIds_002() {
		Logger.start(true, "交易隔离的会员活动");
		try {
			String productId = ProductPriceCallService.getProductIdWithAllPrice();
			
			ProductAllPriceBean productAllPriceBean = ProductPriceCallService.getProdPriceWithActivityInFuture(sellerId,
								productId,MapUtil.hashMap("ActivityTemplateId", ProductPriceCallService.tpl_isolation_Npartcatalog_Nnewbuyer_Member));
				
			if (YmtMongoDriverFactroy.IsNewJavaMongoOpen){
				new ActivityProductsWapper().update(productAllPriceBean.getProductId(), MapUtil.hashMap("part",false,"nbuyer",false,"isolation",true));
				}
				
			
			
			int prodInActivityId = Integer.parseInt(activityProductsWapper.getByProdId(productId).get("inaid").toString());

			//新客 会员价
			ProductPriceBean priceIncludeActivity_NewCust = ProductPriceCallService.getProductPriceBeanByUserLevel(productAllPriceBean,true,false);
			//老客 会员价
			ProductPriceBean priceIncludeActivity_OleCust = ProductPriceCallService.getProductPriceBeanByUserLevel(productAllPriceBean,false,false);
			
			
			//==================================================================================
			//会员政策1， 会员等级3以上才能享受活动价
			ProductPriceCallService.updateActivityMemberPolicy(prodInActivityId, 1, "3,4,5,6");
			
			//IsTradeIsolation= true
			//0级会员 新客 无返回
			JSONObject ret1_1 = getNextActivityPriceByProdIdsCall.callAndGetReturnData(newBuyerId,true,MapUtil.hashMap(productId, prodInActivityId));
			checkRetAsNoPrice(ret1_1, "不满足会员条件，不返回数据");
			
			//6级会员  老客 会员活动价
			JSONObject ret1_2 = getNextActivityPriceByProdIdsCall.callAndGetReturnData(oldBuyerId,true,MapUtil.hashMap(productId, prodInActivityId));
			ProductPriceCallService.checkPriceList(ret1_2, Arrays.asList(priceIncludeActivity_OleCust));
			
			//IsTradeIsolation= false
			//0级会员 新客 无返回
			JSONObject ret1_3 = getNextActivityPriceByProdIdsCall.callAndGetReturnData(newBuyerId,false,MapUtil.hashMap(productId, prodInActivityId));
			checkRetAsNoPrice(ret1_3, "非交易隔离接口查交易隔离活动，不返回数据");
			
			//6级会员  老客 无返回
			JSONObject ret1_4 = getNextActivityPriceByProdIdsCall.callAndGetReturnData(oldBuyerId,false,MapUtil.hashMap(productId, prodInActivityId));
			checkRetAsNoPrice(ret1_4, "非交易隔离接口查交易隔离活动，不返回数据");
			
			
			//==================================================================================
			//会员政策2，会员注册时间在2017-01-02 到 2017-03-23 才能享受活动价
			ProductPriceCallService.updateActivityMemberPolicy(prodInActivityId, 2, "2015-01-02 00:00:00,2016-03-23 23:59:59");
			
			//IsTradeIsolation= true
			//新客 注册时间2015-05-26 14:20:04 会员活动价
			JSONObject ret2_1 = getNextActivityPriceByProdIdsCall.callAndGetReturnData(newBuyerId, true,MapUtil.hashMap(productId, prodInActivityId));
			ProductPriceCallService.checkPriceList(ret2_1, Arrays.asList(priceIncludeActivity_NewCust));
			
			//老客 注册时间2016-04-22 10:19:05 不返回数据
			JSONObject ret2_2 = getNextActivityPriceByProdIdsCall.callAndGetReturnData(oldBuyerId, true,MapUtil.hashMap(productId, prodInActivityId));
			checkRetAsNoPrice(ret2_2, "不满足会员条件，不返回数据");
			
			//IsTradeIsolation= false
			//0级会员 新客 无返回
			JSONObject ret2_3 = getNextActivityPriceByProdIdsCall.callAndGetReturnData(newBuyerId,false,MapUtil.hashMap(productId, prodInActivityId));
			checkRetAsNoPrice(ret2_3, "非交易隔离接口查交易隔离活动，不返回数据");
			
			//6级会员  老客 无返回
			JSONObject ret2_4 = getNextActivityPriceByProdIdsCall.callAndGetReturnData(oldBuyerId,false,MapUtil.hashMap(productId, prodInActivityId));
			checkRetAsNoPrice(ret2_4, "非交易隔离接口查交易隔离活动，不返回数据");
			
		
			//==================================================================================
			//会员政策3， 会员标签满足才能享受活动价  标签值 3 
			ProductPriceCallService.updateActivityMemberPolicy(prodInActivityId,3, "3");
			
			//IsTradeIsolation= true
			//新客 标签3  会员活动价
			JSONObject ret3_1 = getNextActivityPriceByProdIdsCall.callAndGetReturnData(newBuyerId, true,MapUtil.hashMap(productId, prodInActivityId));
			ProductPriceCallService.checkPriceList(ret3_1, Arrays.asList(priceIncludeActivity_NewCust));
			
			//老客 没标签 不返回数据
			JSONObject ret3_2 = getNextActivityPriceByProdIdsCall.callAndGetReturnData(oldBuyerId, true,MapUtil.hashMap(productId, prodInActivityId));
			checkRetAsNoPrice(ret3_2, "不满足会员条件，不返回数据");
			
			//IsTradeIsolation= false
			//0级会员 新客 无返回
			JSONObject ret3_3 = getNextActivityPriceByProdIdsCall.callAndGetReturnData(newBuyerId,false,MapUtil.hashMap(productId, prodInActivityId));
			checkRetAsNoPrice(ret3_3, "非交易隔离接口查交易隔离活动，不返回数据");
			
			//6级会员  老客 无返回
			JSONObject ret3_4 = getNextActivityPriceByProdIdsCall.callAndGetReturnData(oldBuyerId,false,MapUtil.hashMap(productId, prodInActivityId));
			checkRetAsNoPrice(ret3_4, "非交易隔离接口查交易隔离活动，不返回数据");
			
			
			//==============================================================================================
			//会员政策3， 会员标签满足才能享受活动价  标签值 4
			ProductPriceCallService.updateActivityMemberPolicy(prodInActivityId,3, "4");
			
			//新客  标签3  普通价
			JSONObject ret4 =getNextActivityPriceByProdIdsCall.callAndGetReturnData(newBuyerId,true,MapUtil.hashMap(productId, prodInActivityId));
			checkRetAsNoPrice(ret4, "不满足会员条件，不返回数据");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetNextActivityPriceByProdIds_003() {
		Logger.start(true, "非交易隔离的新人活动");
		try {
			String productId = ProductPriceCallService.getProductIdWithAllPrice();
			
			ProductAllPriceBean productAllPriceBean = ProductPriceCallService.getProdPriceWithActivityInFuture(sellerId,
								productId,MapUtil.hashMap("ActivityTemplateId", ProductPriceCallService.tpl_Nisolation_partcatalog_newbuyer));
			
			if (YmtMongoDriverFactroy.IsNewJavaMongoOpen){
				new ActivityProductsWapper().update(productAllPriceBean.getProductId(), MapUtil.hashMap("part",true,"nbuyer",true,"isolation",false,"mlimits",new ArrayList<>()));
			}
				
			
			int prodInActivityId = Integer.parseInt(activityProductsWapper.getByProdId(productId).get("inaid").toString());

			//新客 新客活动价
			ProductPriceBean priceIncludeActivity_NewCust = ProductPriceCallService.getProductPriceBeanByUserLevel(productAllPriceBean,true,false);
			
			//==================================================================================
			//IsTradeIsolation= true
			//新客 活动价 
			JSONObject ret1_1 = getNextActivityPriceByProdIdsCall.callAndGetReturnData(newBuyerId,true,MapUtil.hashMap(productId, prodInActivityId));
			ProductPriceCallService.checkPriceList(ret1_1, Arrays.asList(priceIncludeActivity_NewCust));
			
			//老客 无返回
			JSONObject ret1_2 = getNextActivityPriceByProdIdsCall.callAndGetReturnData(oldBuyerId,true,MapUtil.hashMap(productId, prodInActivityId));
			checkRetAsNoPrice(ret1_2, "老会员不享受活动价，不返回数据");
			
			//IsTradeIsolation= false
			//新客 活动价 
			JSONObject ret1_3 = getNextActivityPriceByProdIdsCall.callAndGetReturnData(newBuyerId,false,MapUtil.hashMap(productId, prodInActivityId));
			ProductPriceCallService.checkPriceList(ret1_3, Arrays.asList(priceIncludeActivity_NewCust));
			
			//老客 无返回
			JSONObject ret1_4 = getNextActivityPriceByProdIdsCall.callAndGetReturnData(oldBuyerId,false,MapUtil.hashMap(productId, prodInActivityId));
			checkRetAsNoPrice(ret1_4, "老会员不享受活动价，不返回数据");
			
			
			
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetNextActivityPriceByProdIds_004() {
		Logger.start(true, "交易隔离的新人活动");
		try {
			String productId = ProductPriceCallService.getProductIdWithAllPrice();
			
			ProductAllPriceBean productAllPriceBean = ProductPriceCallService.getProdPriceWithActivityInFuture(sellerId,
								productId,MapUtil.hashMap("ActivityTemplateId", ProductPriceCallService.tpl_isolation_partcatalog_newbuyer));
				
			if (YmtMongoDriverFactroy.IsNewJavaMongoOpen){
				new ActivityProductsWapper().update(productAllPriceBean.getProductId(), MapUtil.hashMap("part",true,"nbuyer",true,"isolation",true,"mlimits",new ArrayList<>()));
			}
			
			int prodInActivityId = Integer.parseInt(activityProductsWapper.getByProdId(productId).get("inaid").toString());

			//新客 新客活动价
			ProductPriceBean priceIncludeActivity_NewCust = ProductPriceCallService.getProductPriceBeanByUserLevel(productAllPriceBean,true,false);
			
			//==================================================================================
			//IsTradeIsolation= true
			//新客 活动价 
			JSONObject ret1_1 = getNextActivityPriceByProdIdsCall.callAndGetReturnData(newBuyerId,true,MapUtil.hashMap(productId, prodInActivityId));
			ProductPriceCallService.checkPriceList(ret1_1, Arrays.asList(priceIncludeActivity_NewCust));
			
			//老客 无返回
			JSONObject ret1_2 = getNextActivityPriceByProdIdsCall.callAndGetReturnData(oldBuyerId,true,MapUtil.hashMap(productId, prodInActivityId));
			checkRetAsNoPrice(ret1_2, "老会员不享受活动价，不返回数据");
			
			//IsTradeIsolation= false
			//新客 活动价 
			JSONObject ret1_3 = getNextActivityPriceByProdIdsCall.callAndGetReturnData(newBuyerId,false,MapUtil.hashMap(productId, prodInActivityId));
			checkRetAsNoPrice(ret1_3, "非交易隔离接口查交易隔离活动，不返回数据");
			
			//老客 无返回
			JSONObject ret1_4 = getNextActivityPriceByProdIdsCall.callAndGetReturnData(oldBuyerId,false,MapUtil.hashMap(productId, prodInActivityId));
			checkRetAsNoPrice(ret1_4, "老会员不享受活动价，不返回数据");
			
			
			
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetNextActivityPriceByProdIds_005() {
		Logger.start(true, "非交易隔离普通活动");
		try {
			String productId = ProductPriceCallService.getProductIdWithAllPrice();
			
			ProductAllPriceBean productAllPriceBean = ProductPriceCallService.getProdPriceWithActivityInFuture(sellerId,
								productId,MapUtil.hashMap("ActivityTemplateId", ProductPriceCallService.tpl_Nisolation_Npartcatalog_Nnewbuyer));
				
			if (YmtMongoDriverFactroy.IsNewJavaMongoOpen){
				new ActivityProductsWapper().update(productAllPriceBean.getProductId(), MapUtil.hashMap("part",false,"nbuyer",false,"isolation",false,"mlimits",new ArrayList<>()));
			}
			
			
			int prodInActivityId = Integer.parseInt(activityProductsWapper.getByProdId(productId).get("inaid").toString());

			//新客 活动价
			ProductPriceBean priceIncludeActivity_NewCust = ProductPriceCallService.getProductPriceBeanByUserLevel(productAllPriceBean,true,false);
			//老客 活动价
			ProductPriceBean priceIncludeActivity_OleCust = ProductPriceCallService.getProductPriceBeanByUserLevel(productAllPriceBean,false,false);
			
			//==================================================================================
			//IsTradeIsolation= true
			//新客 活动价 
			JSONObject ret1_1 = getNextActivityPriceByProdIdsCall.callAndGetReturnData(newBuyerId,true,MapUtil.hashMap(productId, prodInActivityId));
			ProductPriceCallService.checkPriceList(ret1_1, Arrays.asList(priceIncludeActivity_NewCust));
			
			//老客 活动价
			JSONObject ret1_2 = getNextActivityPriceByProdIdsCall.callAndGetReturnData(oldBuyerId,true,MapUtil.hashMap(productId, prodInActivityId));
			ProductPriceCallService.checkPriceList(ret1_2, Arrays.asList(priceIncludeActivity_OleCust));
			
			//IsTradeIsolation= false
			//新客 活动价 
			JSONObject ret1_3 = getNextActivityPriceByProdIdsCall.callAndGetReturnData(newBuyerId,false,MapUtil.hashMap(productId, prodInActivityId));
			ProductPriceCallService.checkPriceList(ret1_3, Arrays.asList(priceIncludeActivity_NewCust));
			
			//老客 活动价
			JSONObject ret1_4 = getNextActivityPriceByProdIdsCall.callAndGetReturnData(oldBuyerId,false,MapUtil.hashMap(productId, prodInActivityId));
			ProductPriceCallService.checkPriceList(ret1_4, Arrays.asList(priceIncludeActivity_OleCust));
			
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetNextActivityPriceByProdIds_006() {
		Logger.start(true, "交易隔离普通活动");
		try {
			String productId = ProductPriceCallService.getProductIdWithAllPrice();
			
			ProductAllPriceBean productAllPriceBean = ProductPriceCallService.getProdPriceWithActivityInFuture(sellerId,
								productId,MapUtil.hashMap("ActivityTemplateId", ProductPriceCallService.tpl_isolation_Npartcatalog_Nnewbuyer));
				
			if (YmtMongoDriverFactroy.IsNewJavaMongoOpen){
				new ActivityProductsWapper().update(productAllPriceBean.getProductId(), MapUtil.hashMap("part",false,"nbuyer",false,"isolation",true,"mlimits",new ArrayList<>()));
			}
			
			int prodInActivityId = Integer.parseInt(activityProductsWapper.getByProdId(productId).get("inaid").toString());

			//新客 活动价
			ProductPriceBean priceIncludeActivity_NewCust = ProductPriceCallService.getProductPriceBeanByUserLevel(productAllPriceBean,true,false);
			//老客 活动价
			ProductPriceBean priceIncludeActivity_OleCust = ProductPriceCallService.getProductPriceBeanByUserLevel(productAllPriceBean,false,false);
			
			//==================================================================================
			//IsTradeIsolation= true
			//新客 活动价 
			JSONObject ret1_1 = getNextActivityPriceByProdIdsCall.callAndGetReturnData(newBuyerId,true,MapUtil.hashMap(productId, prodInActivityId));
			ProductPriceCallService.checkPriceList(ret1_1, Arrays.asList(priceIncludeActivity_NewCust));
			
			//老客 活动价
			JSONObject ret1_2 = getNextActivityPriceByProdIdsCall.callAndGetReturnData(oldBuyerId,true,MapUtil.hashMap(productId, prodInActivityId));
			ProductPriceCallService.checkPriceList(ret1_2, Arrays.asList(priceIncludeActivity_OleCust));
			
			//IsTradeIsolation= false
			//新客 活动价 
			JSONObject ret1_3 = getNextActivityPriceByProdIdsCall.callAndGetReturnData(newBuyerId,false,MapUtil.hashMap(productId, prodInActivityId));
			checkRetAsNoPrice(ret1_3, "非交易隔离接口查交易隔离活动，不返回数据");
			
			//老客 活动价
			JSONObject ret1_4 = getNextActivityPriceByProdIdsCall.callAndGetReturnData(oldBuyerId,false,MapUtil.hashMap(productId, prodInActivityId));
			checkRetAsNoPrice(ret1_4, "非交易隔离接口查交易隔离活动，不返回数据");
			
			
			
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_GetNextActivityPriceByProdIds_007() {
		Logger.start(true, "测试缓存ExtraDeliveryType,ExtraDeliveryFee");
		try {
			String productId = ProductPriceCallService.getProductIdWithAllPrice();
			
			ProductAllPriceBean productAllPriceBean = ProductPriceCallService.getProdPriceWithActivityInFuture(sellerId,
								productId,MapUtil.hashMap("ActivityTemplateId", ProductPriceCallService.tpl_isolation_Npartcatalog_Nnewbuyer));
				
			if (YmtMongoDriverFactroy.IsNewJavaMongoOpen){
				new ActivityProductsWapper().update(productAllPriceBean.getProductId(), MapUtil.hashMap("part",false,"nbuyer",false,"isolation",true,"mlimits",new ArrayList<>()));
			}
			
			int prodInActivityId = Integer.parseInt(activityProductsWapper.getByProdId(productId).get("inaid").toString());

			//新客 活动价
			ProductPriceBean priceIncludeActivity_NewCust = ProductPriceCallService.getProductPriceBeanByUserLevel(productAllPriceBean,true,false);
			JSONObject ret1 = getNextActivityPriceByProdIdsCall.callAndGetReturnData(newBuyerId,true,MapUtil.hashMap(productId, prodInActivityId));
			ProductPriceCallService.checkPriceList(ret1, Arrays.asList(priceIncludeActivity_NewCust));
			
			//修改ExtraDeliveryType,ExtraDeliveryFee ， 不修改时间戳
			new ProductsWapperV2().updateAll(MapUtil.hashMap("spid",productId), MapUtil.hashMap("mdeliv",2,"mflight",3.1));
			JSONObject ret1_1 = getNextActivityPriceByProdIdsCall.callAndGetReturnData(newBuyerId,true,MapUtil.hashMap(productId, prodInActivityId));
			ProductPriceCallService.checkPriceList(ret1_1, Arrays.asList(priceIncludeActivity_NewCust));
			
			
			//修改时间戳
			//new ProductTimeStampWapper().update(productId, MapUtil.hashMap("sut",new Date()));
			ProductManagerCallServiceV3.updateProductRedisTimeStamp(productId);
			ProductPriceBean priceIncludeActivity_NewCust2 = ProductPriceCallService.getProductPriceBeanByUserLevel(productAllPriceBean,true,false);
			JSONObject ret2 = getNextActivityPriceByProdIdsCall.callAndGetReturnData(newBuyerId,true,MapUtil.hashMap(productId, prodInActivityId));
			ProductPriceCallService.checkPriceList(ret2, Arrays.asList(priceIncludeActivity_NewCust2));
			
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	
	///////////////////  忽略case ///////////
	//渠道商
	private static int rootUserId = AgentUsers.rootUserId;
	private static String rootUserName = "NickautoTest";
	
	@Test
	@Category(P1.class)
	@TestCase
	@Ignore
	public void Tc_GetNextActivityPriceByProdIds_008() {
		Logger.start(true, "查询下一场活动的价格");
		try{
			//创建商品，设置初始库存，
			AddAgentProductBean addAgentProductBean = AddAgentProductCallService.initAddAgentProduct(rootUserId,rootUserName,false);
			Integer catalogNum11 = 1000;
			addAgentProductBean.getCatalogList().forEach(p->{
				p.setStock(catalogNum11);
			});
		 	String productId = AddAgentProductCallService.AddAgentProduct(addAgentProductBean);
		 	//根据数据库查询
		 	ProductDetailsDto selectProductDetails = AddAgentProductCallService.selectProductDetails(rootUserId,productId);
		 	System.out.println(selectProductDetails);
		 	
		 	//获取购买前商品规格库存
			Integer catalogNum = new YmtCatalogsIWapper().selectCatalogsByProductId(productId).get(0).getiNum();
			Integer catalogNum1 = new YmtCatalogsIWapper().selectCatalogsByProductId(productId).get(1).getiNum();
			System.out.println(catalogNum+"    "+catalogNum1);

			List<String> catalogList =new ArrayList<String>();
			selectProductDetails.getCatalogList().forEach(a->{
		 		catalogList.add(a.getCatalogId());
		 	});
			
			//创建限时抢购活动1    昨天到10天后
			AddactivityBean initProductaddactivity = AgentProductCallService.initProductaddactivity(rootUserId, productId, catalogList);
			int activityId = AgentProductCallService.agentProductaddactivity(initProductaddactivity);
		
			//创建限时抢购活动2  11天后-15天后
			AddactivityBean initProductaddactivity1 = AgentProductCallService.initProductaddactivity(rootUserId, productId, catalogList);
			initProductaddactivity1.setBeginTime(YMTDateUtil.getBeforeOrNextDate(11));
			initProductaddactivity1.setEndTime(YMTDateUtil.getBeforeOrNextDate(15));
			initProductaddactivity1.getProductList().forEach(a->{
				a.getCatalogList().forEach(b->{
					b.setDiscount(new BigDecimal("2"));
				});
			});
			int activityId1 = AgentProductCallService.agentProductaddactivity(initProductaddactivity1);
			Thread.sleep(4000);
			
			GetProductInfoByProductIdBean b=new GetProductInfoByProductIdBean();
			b.setNextActivityExpire(7);
			b.setProductId(productId);
			GetProductInfoByProductIdCall getProductInfoByProductIdCall = new GetProductInfoByProductIdCall();
			getProductInfoByProductIdCall.setData(b);
			getProductInfoByProductIdCall.callService();
			JsonObject jsonObject = getProductInfoByProductIdCall.getJsonObject();
			int asInt1 = jsonObject.getAsJsonObject("Data").getAsJsonObject("Product").getAsJsonObject("ProductActivity").get("ProductInActivityId").getAsInt();
			
			
			//减去所有库存
			int reduceNum =1000;
			PCatalogListDto catalogListDto = ProdStockCallService.ReduceStockListForPreOrder(productId, catalogList.get(0), rootUserId, activityId, reduceNum, 0, true);
			PCatalogListDto catalogListDto1 = ProdStockCallService.ReduceStockListForPreOrder(productId, catalogList.get(1), rootUserId, activityId, reduceNum, 0, true);
			Thread.sleep(4000);

			
			
			
			ProductDetailsDto selectProductDetails2 = AddAgentProductCallService.selectProductDetails(rootUserId, productId);
//			JSONObject ret1_1 = getNextActivityPriceByProdIdsCall.callAndGetReturnData(newBuyerId,true,MapUtil.hashMap(productId, asInt));
			JSONObject ret1_2 = getNextActivityPriceByProdIdsCall.callAndGetReturnData(newBuyerId,true,MapUtil.hashMap(productId, asInt1));
//			System.out.println(ret1_1);
			System.out.println(ret1_2);
		}catch(Exception e){
			Logger.fail(e);
		}
	}
	
	
	
	
}
